package com.lzy.cloud.ticket.train.controller;

import com.lzy.cloud.ticket.train.facade.*;
import com.lzy.cloud.ticket.train.response.*;
import com.lzy.framework.core.output.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 回调
 */
@RestController
@RequestMapping(value = "/Callback")
public class TrainCallBackController {

    @Autowired
    private TrainCallBackFacade trainCallBackFacade;

    /**
     * 订单预定回调接口
     */
    @RequestMapping(value = "/booking", method = RequestMethod.POST)
    public Result bookingCallback(@RequestBody BookingOrderCallBackResponse bookingOrderCallBackResponse) {
        Result result = trainCallBackFacade.bookingCallback(bookingOrderCallBackResponse);
        return result;
    }

    /**
     * 订单取消回调接口
     *
     * @return
     *
     */
    @RequestMapping(value = "/cancel", method = RequestMethod.POST)
    public Result cancelTicketCallback(@RequestBody CancleOrderCallBackResponse cancleOrderCallBackResponse) {
        return trainCallBackFacade.cancelTicketCallback(cancleOrderCallBackResponse);
    }


    /**
     * 确认出票回调接口
     */
    @RequestMapping(value = "/confirm", method = RequestMethod.POST)
    public Result confirmTicketCallback(@RequestBody BookingOrderCallBackResponse bookingOrderCallBackResponse) {
        Result result = trainCallBackFacade.confirmTicketCallback(bookingOrderCallBackResponse);
        return result;
    }


    /**
     * 订单退票回调接口
     */
    @RequestMapping(value = "/return", method = RequestMethod.POST)
    public Result returnTicketCallback(@RequestBody BookingOrderCallBackResponse bookingOrderCallBackResponse) {
        Result result = trainCallBackFacade.returnTicketCallback(bookingOrderCallBackResponse);
        return result;
    }


    /**
     * 火车票抢票回调接口
     * TODO 驴妈妈没有提供抢票回调接口
     */
    /*@RequestMapping(value = "/robbing", method = RequestMethod.POST)
    public Result createTicketRobbing(@RequestBody BookingOrderCallBackResponse bookingOrderCallBackResponse) {
        if (!bookingOrderCallBackResponse.getCode().equals("1")){
            return new Result(bookingOrderCallBackResponse.getCode(),bookingOrderCallBackResponse.getErrorMessage(),bookingOrderCallBackResponse.getData());
        }

        return new Result(trainOrderFacade.updateTrainOrder(bookingOrderCallBackResponse));
    }*/

    /**
     * 改签回调接口
     *
     */
    @RequestMapping(value = "/change", method = RequestMethod.POST)
    public Result changeTicketCallback(@RequestBody BookingOrderCallBackResponse bookingOrderCallBackResponse) {
        Result result = trainCallBackFacade.changeTicketCallback(bookingOrderCallBackResponse);
        return result;
    }

}
